import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:schedule_self_client/init.dart';

abstract class AppNotification {
  Future<void> showNotification(int id, String title, String description);

  Future<void> showNotificationWithSound(
      int id, String title, String description);

  factory AppNotification.tomatoClock() {
    return TomatoClockNotification();
  }
}

class TomatoClockNotification implements AppNotification {
  @override
  Future<void> showNotification(
      int id, String title, String description) async {
    if (kIsWeb || Platform.isWindows) {
      return Future.value();
    }
    const AndroidNotificationDetails androidNotificationDetails =
        AndroidNotificationDetails(
      'calendar_alerts',
      '日程提醒',
      channelDescription: '适用于番茄时钟，待办任务截止或超期提醒',
    );
    const DarwinNotificationDetails darwinNotificationDetails =
        DarwinNotificationDetails();
    const LinuxNotificationDetails linuxPlatformChannelSpecifics =
        LinuxNotificationDetails();
    const NotificationDetails notificationDetails = NotificationDetails(
      android: androidNotificationDetails,
      iOS: darwinNotificationDetails,
      macOS: darwinNotificationDetails,
      linux: linuxPlatformChannelSpecifics,
    );
    await flutterLocalNotificationsPlugin.show(
      id,
      title,
      description,
      notificationDetails,
    );
  }

  @override
  Future<void> showNotificationWithSound(
      int id, String title, String description) async {
    if (kIsWeb || Platform.isWindows) {
      return Future.value();
    }
    const AndroidNotificationDetails androidNotificationDetails =
        AndroidNotificationDetails(
      'calendar_alerts',
      '日程提醒',
      channelDescription: '适用于番茄时钟，待办任务截止或超期提醒',
      sound: RawResourceAndroidNotificationSound('slow_spring_board'),
    );
    const DarwinNotificationDetails darwinNotificationDetails =
        DarwinNotificationDetails(
      sound: 'slow_spring_board.aiff',
    );
    final LinuxNotificationDetails linuxPlatformChannelSpecifics =
        LinuxNotificationDetails(
      sound: AssetsLinuxSound('sound/slow_spring_board.mp3'),
    );
    final NotificationDetails notificationDetails = NotificationDetails(
      android: androidNotificationDetails,
      iOS: darwinNotificationDetails,
      macOS: darwinNotificationDetails,
      linux: linuxPlatformChannelSpecifics,
    );
    await flutterLocalNotificationsPlugin.show(
      id,
      title,
      description,
      notificationDetails,
    );
  }
}
